package com.mitest.codediff.command;

import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;

import java.io.File;
import java.util.List;

/**
 * collect mojo report
 *
 * @author shuchao
 * @create 2021-03-01 16:14
 **/
@Mojo(name = "collect-report", defaultPhase = LifecyclePhase.TEST, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
public class CollectReportMojo extends AbstractJacocoMojo {
    @Override
    protected void executeMethod() throws MojoExecutionException, MojoFailureException {
        if (!canGenerateReport()) {
            return;
        }
        System.out.println("开始：collect-report");
        System.out.println(this.getProject().toString());

        // 获取项目依赖
        List<Dependency> dependencies = this.getProject().getDependencies();

        // 遍历并打印依赖
        for (org.apache.maven.model.Dependency dependency : dependencies) {
            getLog().info(String.format("GroupId: %s, ArtifactId: %s, Version: %s",
                    dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()));
        }


    }
}
